import { getRouter } from "@/api/router";
import { getFilterRouter } from "@/utils/router";
import user from "./user";

const state = {
  router: [],
};

const getters = {
  router: (state: any) => state.router,
};

const mutations = {
  setRouter(state: any, router: any) {
    state.router = router;
  },
};

const actions = {
  async setRouter(context: any) {
    const { data } = await getRouter();
    const routes = getFilterRouter(user.state.role, data);
    context.commit("setRouter", routes);
    return routes;
  },
};

export default { state, getters, mutations, actions };
